package com.app.interceptor;

import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
import org.slf4j.Logger;  
import org.slf4j.LoggerFactory;  
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 

public class CommonInterceptor extends HandlerInterceptorAdapter{   
    private static final Logger LOGGER = LoggerFactory.getLogger(CommonInterceptor.class);  
     @Override      
        public boolean preHandle(HttpServletRequest request,      
                HttpServletResponse response, Object handler) throws Exception {      
           String path = request.getServletPath();
            if(path.contains("login")){
            	return true;
            }
            String username =  (String)request.getSession().getAttribute("user");     
            if(username == null){    
                LOGGER.info("Interceptor：跳转到login页面！");    
                //request.getRequestDispatcher("/view/login.jsp").forward(request, response);  //此时web.xml url-pattern为/*   
                request.getRequestDispatcher("/web/login").forward(request, response);
                return false;    
            }else    
                return true;       
        }      
}  
